package hello.world;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

/**
 * @author Demián Gutierrez
 */
public class HelloWorld extends Activity {

  // --------------------------------------------------------------------------------
  // UI using the xml layout
  // --------------------------------------------------------------------------------

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
  }

  // --------------------------------------------------------------------------------
  // Same UI, but NOT using the xml layout (coding UI by hand)
  // --------------------------------------------------------------------------------

  //  private EditText txtInput;
  //  private TextView lblHello;
  //
  //  @Override
  //  protected void onCreate(Bundle savedInstanceState) {
  //    super.onCreate(savedInstanceState);
  //
  //    // ------------------------------------------
  //    // Very similar to swing
  //    // ------------------------------------------
  //
  //    LinearLayout mainPanel = new LinearLayout(this);
  //    mainPanel.setOrientation(LinearLayout.VERTICAL);
  //    setContentView(mainPanel);
  //
  //    txtInput = new EditText(this);
  //    txtInput.setText(getString(R.string.input));
  //    txtInput.setGravity(Gravity.CENTER_HORIZONTAL);
  //    mainPanel.addView(txtInput);
  //
  //    Button btnSayHi = new Button(this);
  //    btnSayHi.setText(getString(R.string.sayhi));
  //    btnSayHi.setGravity(Gravity.CENTER_HORIZONTAL);
  //    btnSayHi.setOnClickListener(new View.OnClickListener() {
  //      public void onClick(View view) {
  //        btnSayHiClicked(view);
  //      }
  //    });
  //    mainPanel.addView(btnSayHi);
  //
  //    lblHello = new TextView(this);
  //    lblHello.setText(getString(R.string.hello));
  //    lblHello.setGravity(Gravity.CENTER_HORIZONTAL);
  //    mainPanel.addView(lblHello);
  //  }

  // --------------------------------------------------------------------------------
  // The button event handler
  // --------------------------------------------------------------------------------

  public void btnSayHiClicked(View view) {
    // ------------------------------------------
    // Comment this when NOT using the xml layout
    // ------------------------------------------
    TextView lblHello = (TextView) findViewById(R.id.lblHello);
    EditText txtInput = (EditText) findViewById(R.id.txtInput);
    // ------------------------------------------

    lblHello.setText("Hello " + txtInput.getText() + "!!!");
  }
}
